package com.talent.core.protocol.mqtt.codec.encoder;

import com.talent.core.protocol.mqtt.model.response.TlMqttPubRel;
import com.talent.core.protocol.mqtt.model.variable.TlMqttPubRelVariableHead;
import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandler;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.MessageToByteEncoder;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * @ClassName：TlConnectDecoder
 * @Author: hszhou
 * @Date: 2024/11/30 15:12
 * @Description: 必须描述类做什么事情, 实现什么功能
 */
@ChannelHandler.Sharable
public class TlMqttPubRelEncoder extends MessageToByteEncoder<TlMqttPubRel> {

    private static final  Logger logger = LoggerFactory.getLogger(TlMqttPubRelEncoder.class);




    @Override
    protected void encode(ChannelHandlerContext ctx, TlMqttPubRel res, ByteBuf out) throws Exception {
        logger.debug("进入【PUBREC】的编码器编码消息");
        TlMqttPubRelVariableHead variableHead = res.getVariableHead();

        //回复订阅
        int type= res.getFixedHead().getMessageType()<<4;
        //消息类型
        out.writeByte(type);
        //剩余长度
        out.writeByte(res.getFixedHead().getLength());
        out.writeShort(variableHead.getMessageId());
    }
}
